package org.eproject.core.well.command;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.eproject.core.well.delegate.PageInfo;
import org.eproject.core.well.delegate.UserDeleGate;
import org.eproject.core.well.exception.CommandException;
import org.eproject.core.well.exception.DeleGateException;
import org.eproject.core.well.exception.FactoryException;
import org.eproject.core.well.factory.Simplefactory;
import org.eproject.core.well.viewhelp.Helper;

public class UserListCommand implements ICommand{

	public String execute(Helper h) throws CommandException {
		HttpSession session = h.getReq().getSession();
		PageInfo pi = (PageInfo)session.getAttribute("pageinfo");
		String pagesize = (String)h.getData().get("pagesize");
		String pagecrre = (String)h.getData().get("pagecrre");
		try {
			UserDeleGate ud = (UserDeleGate)Simplefactory.creatorBean("userdelegate");
			if(pi != null&&pagesize != null){
				pi.setPagecrre(pagecrre==null? 1:Integer.valueOf(pagecrre));
				pi.setPagesize(pagesize==null? 8:Integer.valueOf(pagesize));
			}else{
				pi = ud.initPageInfo(pagesize==null ? 8:Integer.valueOf(pagesize));
				session.setAttribute("pageinfo",pi);
			}
			List lu = (List)ud.getByPage(pi);
			h.getReq().setAttribute("userbypage",lu);
			System.out.print(lu.size());
			return "/eproject/main/sysadmin/usermananger.jsp";
		} catch (FactoryException e) {
			e.printStackTrace();
			throw new CommandException(e);
		} catch (NumberFormatException e) {
			e.printStackTrace();
			throw new CommandException(e);
		} catch (DeleGateException e) {
			e.printStackTrace();
			throw new CommandException(e);
		}
	}
}
